package com.cskaoyan.javase.oop3._1interface._4example.operation.controller.impl;

import com.cskaoyan.javase.oop3._1interface._4example.model.Goods;
import com.cskaoyan.javase.oop3._1interface._4example.operation.controller.IGoodsOperation;
import com.cskaoyan.javase.oop3._1interface._4example.operation.dao.IGoodsDao;
import com.cskaoyan.javase.oop3._1interface._4example.operation.dao.impl.IGoodsDaoImpl;

/**
 * 商品操作接口的实现类
 * 所以商品操作都需要该对象支持
 * 这里分包,只做业务操作,不做数据处理
 *
 * @since 11:22
 * @author wuguidong@cskaoyan.onaliyun.com
 */
public class IGoodsOperationImpl implements IGoodsOperation {

    // 该类中所有数据处理的操作都依赖与dao层下的商品数据处理对象
    private IGoodsDao ig = new IGoodsDaoImpl();

    /**
     * 把所有商品对象展示出来,排除null元素
     * @return com.cskaoyan.javase.oop3._1interface._4example.model.Goods[]
     * @author wuguidong@cskaoyan.onaliyun.com
     * @since 2022/05/20 11:25
     */
    @Override
    public Goods[] getRealGoods() {
        return ig.getRealGoods();
    }

    /**
     * 插入一条商品信息
     * @param id 插入的id
     * @param name
     * @param price
     * @param brand
     * @return int
     * @author wuguidong@cskaoyan.onaliyun.com
     * @since 2022/05/20 11:40
     */
    @Override
    public int createGoods(int id, String name, double price, String brand) {
        Goods goodsInsert = new Goods(id, name, price, brand);
        return ig.createGoods(goodsInsert);
    }

    /**
     * 根据商品的唯一性标识id 删除一条商品信息
     * @param id
     * @return boolean
     * @author wuguidong@cskaoyan.onaliyun.com
     * @since 2022/05/20 14:27
     */
    @Override
    public boolean deleteGoods(int id) {
        return ig.deleteGoods(id);
    }
}
